<cfmodule template="../../tag/layout.cfm">
<script type="text/javascript" charset="utf-8" src="assets/js/fwExtEasyUIDatagrid.js"></script>
<table id="grid"></table>
<div id="toolbar" style="display: none;">
	<form id="searchForm">
		<table>
			<tr>
				<td>标题</td>
				<td><input name="subject" style="width: 180px;" /></td>
				<td>创建时间</td>
				<td>
					<input name="created_ge"  class="easyui-datebox" style="width:100px"/>
					-
					<input name="created_le"  class="easyui-datebox" style="width:100px"/>
				</td>
				<td>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',fw.serializeObject($('#searchForm')));">过滤</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
				</td>
			</tr>
		</table>
	</form>
	<table>
		<tr>
			<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">发送消息</a>
			</td>
		</tr>
	</table>
</div>
</cfmodule>
<script type="application/javascript">
	//查看操作
	var showFun = function(id) {
		url ='?action=sms.form&id=' + id;
	    var dialog = parent.fw.modalDialog({
	        title: '查看记录',
	        url: url,
	       	width:800,
	        height:700,
	        buttons: [
	        {
	            text: '回复消息',
	            handler: function() {
	                dialog.find('iframe').get(0).contentWindow.replyDialog(dialog, grid, parent.$);
	            }
	        },{
	            text: '关闭窗口',
	            handler: function() {
	                dialog.find('iframe').get(0).contentWindow.readDialog(dialog,grid);
	            }
	        }]
	    });
	};
	
	
	//新增操作
	var addFun = function() {
	    var dialog = parent.fw.modalDialog({
	        title: '发送消息',
	        url: '?action=sms.form',
	        width:800,
	        height:700,
	        buttons: [
	        {
	            text: '发送消息',
	            handler: function() {
	                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
	            }
	        },{
	            text: '关闭窗口',
	            handler: function() {
	               dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
	            }
	        }]
	    });
	}
	
	//删除操作
	var removeFun = function(id) {
	    parent.$.messager.confirm('询问', '您确定要删除此记录？',
	    function(r) {
	        if (r) {
	            $.post('?action=sms.deleteinbox', {
	                id: id
	            },
	            function(result) {
	                grid.datagrid('reload');
	            },
	            'json');
	        }
	    });
	};

	$(function(){
		//列表操作
		var gird;
		grid = $('#grid').datagrid({
			fit: true,
			border:false,
			collapsible:false,
			pagination:true,
			singleSelect:true,
			rownumbers:true,
			sortName:'id',
			idField:'id',
			sortOrder:'desc',
			toolbar : '#toolbar',
			url:'?action=sms.getInBoxList',
			columns:[[
				{field:'id',title:'ID',width:40,sortable:true},
				{field:'subject',title:'标题',width:300},
				{field:'fromusername',title:'发件人',width:80},
				{field:'readed',title:'阅读时间',width:80,align:'center',sortable:true},
				{field:'created',title:'发送时间',width:80,align:'center',sortable:true},
				{
					title : '操作',
					field : 'action',
					width : '60',
					align:'center',
					formatter : function(value, row) {
						var str = '';
						str += fw.formatString('<img class="iconImg ext-icon-note" title="查看" onclick="showFun(\'{0}\');"/>', row.id);
						str += fw.formatString('<img class="iconImg ext-icon-note_delete" title="删除" onclick="removeFun(\'{0}\');"/>', row.id);
						return str;
					}
				} 
			]],
			onLoadSuccess : function(data) {
				$('.iconImg').attr('src', fw.pixel_0);
			}
		});
		
	});
</script>